package com.example.demo1.service;
import com.example.demo1.entity.Book;
import com.example.demo1.mapper.BookMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class BookService {
    @Autowired
    private BookMapper bookMapper;

    public int addBook(Book book){
        String state = book.getStatu();
        switch (state) {
            case "可借阅": book.setStatu("0"); break;
            case "已借出": book.setStatu("1"); break;
            case "已下架": book.setStatu("2"); break;
            default: book.setStatu("0"); // 默认值（根据业务调整）
        }
        int num = bookMapper.addBook(book);
        return num;
    }

    public int deleteBook(Integer id){
        int num = bookMapper.deleteBook(id);
        return num;
    }

    public int updateBook(Book book){
        int num = bookMapper.updateBook(book);
        return num;
    }

    public Book selectBook(Integer id){
        return bookMapper.selectBook(id);
    }

    public ArrayList <Book> selectBooks(Book book){
        return bookMapper.selectBooks(book);
    }

}
